import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true,
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
  },

  {
    path: '/a',
    component: Layout,
    redirect: '/a/detail',
    hidden: false,
    meta: { title: '项目详情', icon: 'dashboard' },
    children: [{
      path: 'detail',
      name: 'detail',
      component: () => import('@/views/projectDetail/index'),
      meta: { title: '项目详情', icon: 'dashboard' }
    }]
  },


  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/index',
  //   hidden:false,
  //   meta: { title: '首页', icon: 'dashboard' },
  //   children: [{
  //     path: 'index',
  //     name: 'index',
  //     component: () => import('@/views/home/index'),
  //     meta: { title: '首页', icon: 'dashboard' }
  //   }]
  // },
  // {
  //   path: '/project',
  //   component: Layout,
  //   redirect: '/project/projectManagement',
  //   name: 'project',
  //   meta: { title: '项目管理', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'projectManagement',
  //       name: 'projectManagement',
  //       component: () => import('@/views/projectManagement/index'),
  //       meta: { title: '项目列表', icon: 'table' }
  //     }
  //   ]
  // },
  // {
  //   path: '/audit',
  //   component: Layout,
  //   redirect: '/audit/auditManagement',
  //   name: 'audit',
  //   meta: { title: '审核管理', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'auditManagement',
  //       name: 'auditManagement',
  //       component: () => import('@/views/auditManagement/index'),
  //       meta: { title: '审核列表', icon: 'table' }
  //     }
  //   ]
  // },
  // {
  //   path: '/miniProgram',
  //   component: Layout,
  //   redirect: '/miniProgram/miniProgramManagement',
  //   name: 'miniProgram',
  //   meta: { title: '小程序管理', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'miniProgramManagement',
  //       name: 'miniProgramManagement',
  //       component: () => import('@/views//miniProgramManagement/index'),
  //       meta: { title: '小程序配置', icon: 'table' }
  //     }
  //   ]
  // },
  // // 用户管理
  // {
  //   path: '/mini_user',
  //   component: Layout,
  //   name: 'user',
  //   meta: { title: '小程序用户管理', icon: 'el-icon-user' },
  //   children: [{
  //     path: 'list',
  //     name: 'userList',
  //     component: () => import('@/views/permissionPage/mini_user/index'),
  //     meta: { title: '小程序用户列表', icon: 'el-icon-user' }
  //   }]
  // },
  // // 企业用户管理
  // {
  //   path: '/inside_user',
  //   component: Layout,
  //   name: 'user',
  //   meta: { title: '企业用户管理', icon: 'el-icon-user' },
  //   children: [{
  //     path: 'list',
  //     name: 'userList',
  //     component: () => import('@/views/permissionPage/inside_user/index'),
  //     meta: { title: '企业用户列表', icon: 'el-icon-user' }
  //   }]
  // },
  // // 施工方用户管理
  // {
  //   path: '/worker_user',
  //   component: Layout,
  //   name: 'user',
  //   meta: { title: '施工方用户管理', icon: 'el-icon-user' },
  //   children: [{
  //     path: 'list',
  //     name: 'userList',
  //     component: () => import('@/views/permissionPage/worker_user/index'),
  //     meta: { title: '施工方用户列表', icon: 'el-icon-user' }
  //   }]
  // },
  // // 品牌方管理
  // {
  //   path: '/brand_user',
  //   component: Layout,
  //   name: 'user',
  //   meta: { title: '品牌方管理', icon: 'el-icon-user' },
  //   children: [{
  //     path: 'nodeManagement',
  //     name: 'nodeManagement',
  //     component: () => import('@/views/nodeManagement/index'),
  //     meta: { title: '节点库管理', icon: 'el-icon-user' }
  //   }, {
  //     path: 'checkManagement',
  //     name: 'checkManagement',
  //     component: () => import('@/views/checkManagement/index'),
  //     meta: { title: '标准库管理', icon: 'el-icon-user' }
  //   }, {
  //     path: 'templateManagement',
  //     name: 'templateManagement',
  //     component: () => import('@/views/templateManagement/index'),
  //     meta: { title: '模板库管理', icon: 'el-icon-user' }
  //   }, {
  //     path: 'brandList',
  //     name: 'brandList',
  //     component: () => import('@/views/brandManagement/index'),
  //     meta: { title: '品牌列表', icon: 'el-icon-user' }
  //   }, {
  //     path: 'list',
  //     name: 'userList',
  //     component: () => import('@/views/permissionPage/brand_user/index'),
  //     meta: { title: '品牌方用户列表', icon: 'el-icon-user' }
  //   }]
  // },
  // {
  //   path: '/system',
  //   component: Layout,
  //   name: 'system',
  //   meta: { title: '系统管理', icon: 'el-icon-setting' },
  //   children: [{
  //     path: '/role_list',
  //     name: 'role_list',
  //     component: () => import('@/views/permissionPage/role/index'),
  //     meta: { title: '权限管理', icon: 'el-icon-s-custom' }
  //   }
  //   ]
  // },
  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  //       meta: { title: 'External Link', icon: 'link' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true },
]
const createRouter = () => new Router({
  // base: "/client/",
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
